package com.fangtao.test;

import java.util.Date;

import cn.hutool.core.date.DateUtil;
import io.netty.bootstrap.Bootstrap;
import io.netty.channel.Channel;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioSocketChannel;
import io.netty.handler.codec.string.StringEncoder;

public class GpsClient {

	public static void main(String[] args) throws InterruptedException {
		
		Bootstrap bootstrap = new Bootstrap();
		NioEventLoopGroup group = new NioEventLoopGroup();

		bootstrap.group(group).channel(NioSocketChannel.class).handler(new ChannelInitializer<Channel>() {
			@Override
			protected void initChannel(Channel ch) {
				ch.pipeline().addLast(new StringEncoder());
			}
		});

		Channel channel = bootstrap.connect("120.79.90.112", 8666).channel();
		//Channel channel = bootstrap.connect("127.0.0.1", 8666).channel();
		
//		channel.pipeline().addLast(new StringDecoder());
//		channel.pipeline().addLast(new ChannelInboundHandlerAdapter() {
//			@Override
//			public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
//				System.out.println(msg);
//			}
//		});
		
		while (true) {
			channel.writeAndFlush(DateUtil.format(new Date(), "yyyy年MM月dd日 HH:mm:ss"));
			Thread.sleep(500);
		}
		
	}

}
